    #include<iostream>
    #include<algorithm>
    #include<cstring>

    using namespace std;
    const int N = 210, INF = 0x3f3f3f3f;

    int n, m, k;
    int g[N][N];


    int main(){
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);


        memset(g, 0x3f, sizeof g);

        for (int i = 1; i <= n; i ++){
            g[i][i] = 0;
        }
        
        scanf("%d%d%d", &n, &m, &k);

        

        for (int i = 0; i < m; i ++){
            int x, y, z;
            scanf("%d%d%d", &x, &y, &z);
            g[x][y] = min(g[x][y], z);
        }

        for (int p = 1; p <= n; p ++){
            for (int i = 1; i <= n; i ++){
                for (int j = 1; j <= n; j ++){
                    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
                }
            }
        }

        for (int i = 0; i < k; i ++){
            int x, y;
            scanf("%d%d", &x, &y);
            if(g[x][y] == INF){
                printf("impossible\n");
            }else{
                printf("%d\n", g[x][y]);
            }
        }

        return 0;
    }